home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-17 | 4.8 KB | 216 lines | [TEXT/MPS ] |
- {
- ShowHideMBar.p
- MPW 3.0 Pascal unit to hide the menu bar
- Copyright © 1989 D. Grant Leeper.
- All rights reserved.
- Publication rights granted to MacTutor.
-
- NOTE: The calling application is responsible for
- insuring that the menu bar is left visible after
- suspending and quitting!
-
- CAUTION: This code violates the guidelines for
- future compatibility, use it at your own risk.
- Specifically it modifies the GrayRgn and
- MBarHeight global variables, and paints and
- manipulates the window manager port.
- Also, since it modifies MBarHeight it requires
- the 128K (or newer) ROMs.
- }
-
- UNIT ShowHideMBar;
-
- INTERFACE
-
- USES
- Types, QuickDraw, Events,
- Controls, Windows, Menus;
-
- PROCEDURE HideMenuBar;
-
- PROCEDURE ShowMenuBar;
-
- FUNCTION MenuBarVisible: BOOLEAN;
-
- FUNCTION PtInMenuBar(pt: Point): BOOLEAN;
-
- FUNCTION HiddenMenuSelect
- (startPt: Point): LONGINT;
-
- IMPLEMENTATION
-
- VAR
- gSavedMBarHeight: INTEGER;
- (*
- CONST
- GrayRgn = $09EE;
- MBarHeight = $0BAA;
-
- { Defined in Windows.p }
- FUNCTION GetGrayRgn: RgnHandle;
- INLINE $2EB8, $09EE; { MOVE.L GrayRgn,(SP) }
- *)
- { Defined in Script.p }
- FUNCTION GetMBarHeight: INTEGER;
- INLINE $3EB8, $0BAA; { MOVE MBarHeight,(SP) }
-
- PROCEDURE SetMBarHeight(height: INTEGER);
- INLINE $31DF, $0BAA; { MOVE (SP)+,MBarHeight }
-
- FUNCTION GetWindowList: WindowPtr;
- INLINE $2EB8, $9D6; { MOVE.L WindowList,(SP) }
-
- {$S ShowHideMBar}
- FUNCTION GetMBarRgn: RgnHandle;
-
- VAR
- r: Rect;
- worldRgn: RgnHandle;
- mBarRgn: RgnHandle;
-
- BEGIN
- { Compute worldRgn, the round cornered
- rectangle that bounds all screens }
- r := GetGrayRgn^^.rgnBBox;
- UnionRect(r, screenBits.bounds, r);
- worldRgn := NewRgn;
- OpenRgn;
- FrameRoundRect(r, 16, 16);
- CloseRgn(worldRgn);
-
- { Compute mBarRgn, the intersection
- of the menu bar's rectangle with
- worldRgn. }
- r := screenBits.bounds;
- r.bottom := r.top + gSavedMBarHeight;
- mBarRgn := NewRgn;
- RectRgn(mBarRgn, r);
- SectRgn(worldRgn, mBarRgn, mBarRgn);
-
- DisposeRgn(worldRgn);
- GetMBarRgn := mBarRgn
- END; { GetMBarRgn }
-
- {$S ShowHideMBar}
- PROCEDURE HideMenuBar;
-
- VAR
- mBarHeight: INTEGER;
- grayRgn: RgnHandle;
- menuBarRgn: RgnHandle;
- startWindow: WindowPeek;
-
- BEGIN
- mBarHeight := GetMBarHeight;
- IF mBarHeight <> 0 THEN
- BEGIN
- grayRgn := GetGrayRgn;
- { GSavedMBarHeight must be valid
- when calling GetMBarRgn }
- gSavedMBarHeight := mBarHeight;
- menuBarRgn := GetMBarRgn;
- SetMBarHeight(0);
- { Add menuBarRgn to GrayRgn. }
- UnionRgn(grayRgn, menuBarRgn, grayRgn);
- { Now tell the Window Manager that the
- desktop has expanded, so the area
- under the menu bar will get
- updated correctly. We do this by
- calling two of the low-level
- Window Manager routines PaintBehind
- and CalcVisBehind. }
- startWindow := WindowPeek(GetWindowList);
- { PaintBehind redraws the desktop,
- including window frames, as made
- necessary by the removal of the menu
- bar. It also generates the needed
- window update events. }
- PaintBehind(startWindow, menuBarRgn);
- { CalcVisBehind recalculates any window
- visRgns that need to be changed to
- allow for the removal of the menu bar. }
- CalcVisBehind(startWindow, menuBarRgn);
- DisposeRgn(menuBarRgn)
- END { IF }
- END; { HideMenuBar }
-
- {$S ShowHideMBar}
- PROCEDURE ShowMenuBar;
-
- VAR
- grayRgn: RgnHandle;
- menuBarRgn: RgnHandle;
-
- BEGIN
- IF GetMBarHeight = 0 THEN
- BEGIN
- grayRgn := GetGrayRgn;
- menuBarRgn := GetMBarRgn;
- SetMBarHeight(gSavedMBarHeight);
- { Remove menuBarRgn from GrayRgn }
- DiffRgn(grayRgn, menuBarRgn, grayRgn);
- { Now tell the Window Manager that the
- menu bar is no longer part of the
- desktop. We do this by calling
- CalcVisBehind again. We do not need
- to call PaintBehind first because we
- are not expanding the desktop. }
- CalcVisBehind(WindowPeek(GetWindowList),
- menuBarRgn);
- DisposeRgn(menuBarRgn);
- { Now redraw the menu bar on the
- desktop. }
- DrawMenuBar
- END { IF }
- END; { ShowMenuBar }
-
- {$S ShowHideMBar}
- FUNCTION MenuBarVisible: BOOLEAN;
-
- BEGIN
- MenuBarVisible := GetMBarHeight <> 0
- END; { MenuBarVisible }
-
- {$S ShowHideMBar}
- FUNCTION PtInMenuBar(pt: Point): BOOLEAN;
-
- VAR
- height: INTEGER;
- r: Rect;
-
- BEGIN
- height := GetMBarHeight;
- IF height = 0 THEN
- { Menu bar is hidden. }
- height := gSavedMBarHeight;
- r := screenBits.bounds;
- r.bottom := r.top + height;
- PtInMenuBar := PtInRect(pt, r)
- END; { PtInMenuBar }
-
- {$S ShowHideMBar}
- FUNCTION HiddenMenuSelect
- (startPt: Point): LONGINT;
-
- VAR
- wasHidden: BOOLEAN;
-
- BEGIN
- wasHidden := GetMBarHeight = 0;
- IF wasHidden THEN
- { Change it temporarily. }
- SetMBarHeight(gSavedMBarHeight);
- { Now do normal MenuSelect }
- HiddenMenuSelect := MenuSelect(startPt);
- IF wasHidden THEN
- BEGIN
- { We must unhilite the menu ourselves
- before setting MBarHeight back to 0. }
- HiliteMenu(0);
- { Now change it back. }
- SetMBarHeight(0)
- END { IF }
- END; { HiddenMenuSelect }
-
- END. { ShowHideMBar }
-